﻿using AutoMapper;
using MediatR;
using Traceability.App.Api.Application.Command.Detail.Cultivation;
using Traceability.App.ErrorCount;
using Traceability.App.InfrasIntructure;
using Traceability.App.Model.Cultivation;

namespace Traceability.App.Api.Application.Handler.Detail.Cultivation
{
    public class AddImmunityHandler : IRequestHandler<AddImmunityCommand, ApiResult<int>>
    {
        IBaseRepository<ImmunityModel> immRepo;
       

        public AddImmunityHandler(IBaseRepository<ImmunityModel> immRepo)
        {
            this.immRepo = immRepo;
            
        }

        public async Task<ApiResult<int>> Handle(AddImmunityCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> res=new ApiResult<int>();
            var model = await immRepo.AddAll(request.immunityModels);
            res.Datas = model;
            res.Code = model > 0 ? ApiEnum.Success : ApiEnum.Fail;
            res.Msg = model > 0 ? "添加免疫信息成功" : "添加免疫信息失败";
            return  await Task.FromResult(res);
        }
    }
}
